package com.dreamer.view.pyramid;

import com.dreamer.domain.account.AccountsName;
import com.dreamer.domain.pyramid.ParamConfig;
import com.dreamer.service.pyramid.AccountsNameHandler;
import com.dreamer.service.pyramid.ParamConfigHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ps.mx.otter.utils.message.Message;

import java.util.Date;
import java.util.Optional;

@RestController
@RequestMapping("/accountsName")
public class AccountsNameController {

    @Autowired
    private AccountsNameHandler accountsNameHandler;

    @RequestMapping(value = "/edit.json", method = RequestMethod.POST)
    public Message edit(@ModelAttribute("parameter") AccountsName accountsName) {
        AccountsName accountsName1 = accountsNameHandler.saveOrupdate(accountsName);
        if(accountsName1 != null){
            return Message.createSuccessMessage();
        }else{
            return Message.createFailedMessage();
        }
    }

    @ModelAttribute("parameter")
    public AccountsName preprocess(@RequestParam("id") Optional<Integer> id) {
        AccountsName accountsName;
        if (id.isPresent()) {
            accountsName = accountsNameHandler.findById(id.get());
        }else{
            accountsName = new AccountsName();
        }
        return accountsName;
    }

}
